package com.xjgz.aio.socket.transport;

import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.function.Consumer;

public interface WriteBuffer extends Closeable {

    default void write(int b) {
        writeByte((byte) b);
    }

    void writeByte(byte b);

    void writeShort(short s) throws IOException;

    void writeInt(int i) throws IOException;

    void writeLong(long l) throws IOException;

    default void write(byte[] b) throws IOException {
        write(b, 0, b.length);
    }

    void write(byte[] b, int off, int len) throws IOException;

    void write(byte[] b, int off, int len, Consumer<WriteBuffer> consumer) throws IOException;

    default void write(byte[] b, Consumer<WriteBuffer> consumer) throws IOException {
        write(b, 0, b.length, consumer);
    }

    void transferFrom(ByteBuffer byteBuffer, Consumer<WriteBuffer> consumer) throws IOException;

    void flush();
}
